package com.orm.pool;

import com.orm.mapping.Configuration;
import lombok.extern.slf4j.Slf4j;

import javax.sql.DataSource;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;


/**
 * 测试用的
 */

@Slf4j
public class MyDataSource implements DataSource {
	
	private Environment env;
	
	public MyDataSource(Environment env) {
		this.env = env;
		
	}
	
	@Override
	public Connection getConnection() throws SQLException {
		log.info("从JDBC打开了一个数据库连接...");
		return DriverManager.getConnection(env.getUrl(),env.getUsername(),env.getPassword());
	}
	
	
	/**
	 * 下面的全部都不管，不实现，只用上面这一个 getConnection() 方法
	 * @param username
	 * @param password
	 * @return
	 * @throws SQLException
	 */
	@Override
	public Connection getConnection(String username, String password) throws SQLException {
		return null;
	}
	
	@Override
	public <T> T unwrap(Class<T> iface) throws SQLException {
		return null;
	}
	
	@Override
	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		return false;
	}
	
	@Override
	public PrintWriter getLogWriter() throws SQLException {
		return null;
	}
	
	@Override
	public void setLogWriter(PrintWriter out) throws SQLException {
	
	}
	
	@Override
	public void setLoginTimeout(int seconds) throws SQLException {
	
	}
	
	@Override
	public int getLoginTimeout() throws SQLException {
		return 0;
	}
	
	@Override
	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
		return null;
	}
}
